<template>
    <div style="height: 100%;">
        <div class="searchDiv">
            <DateRange v-model:start="obj.req.start" v-model:end="obj.req.end" sph="起止时间" />
            <span class="search" @click="init"></span>
            <div class="searchRight">
                <span class="refresh" @click="obj.req.currentpage=1;init()"></span>
            </div>
        </div>
        <div>
            <div ref="img2_1" style="width: 500px; height: 500px; float: left;"></div>
            <div ref="img2_2" style="width: 600px; height: 500px; float: left;"></div>
        </div>
    </div>
</template>

<script setup>
    import { reactive, getCurrentInstance, ref, toRefs, onMounted, nextTick } from 'vue'
    import DateRange from '@/components/date_range.vue'
    let { proxy } = getCurrentInstance()
    let obj = reactive({
        ary: [],
        req: {
            currentpage: 1,
            pagesize: 10,
            count: 0,
            start:"",
            end:"",
        }
    });

    onMounted(() => {
        var myChart1 = proxy.$echarts.init(proxy.$refs["img2_1"]);
        let option1 = {
            series: [
                {
                type: 'gauge',
                startAngle: 180,
                endAngle: 0,
                min: 0,
                max: 1,
                splitNumber: 8,
                axisLine: {
                    lineStyle: {
                    width: 6,
                    color: [
                        [0.25, '#FF6E76'],
                        [0.5, '#FDDD60'],
                        [0.75, '#58D9F9'],
                        [1, '#7CFFB2']
                    ]
                    }
                },
                pointer: {
                    icon: 'path://M12.8,0.7l12,40.1H0.7L12.8,0.7z',
                    length: '12%',
                    width: 20,
                    offsetCenter: [0, '-60%'],
                    itemStyle: {
                    color: 'auto'
                    }
                },
                axisTick: {
                    length: 12,
                    lineStyle: {
                    color: 'auto',
                    width: 2
                    }
                },
                splitLine: {
                    length: 20,
                    lineStyle: {
                    color: 'auto',
                    width: 5
                    }
                },
                axisLabel: {
                    color: '#464646',
                    fontSize: 20,
                    distance: -60,
                    formatter: function (value) {
                    if (value === 0.875) {
                        return 'A';
                    } else if (value === 0.625) {
                        return 'B';
                    } else if (value === 0.375) {
                        return 'C';
                    } else if (value === 0.125) {
                        return 'D';
                    }
                    return '';
                    }
                },
                title: {
                    offsetCenter: [0, '-20%'],
                    fontSize: 30
                },
                detail: {
                    fontSize: 20,
                    offsetCenter: [0, '0%'],
                    valueAnimation: true,
                    formatter: function (value) {
                        return Math.round(value * 100) + '分';
                    },
                    color: 'auto'
                },
                data: [
                    {
                    value: 0.7,
                    name: 'Grade Rating'
                    }
                ]
                }
            ]
        };
        option1 && myChart1.setOption(option1);

        var myChart2 = proxy.$echarts.init(proxy.$refs["img2_2"]);
        let dataAxis = ['点', '击', '柱', '子', '或', '者', '两', '指', '在', '触', '屏', '上', '滑', '动', '能', '够', '自', '动', '缩', '放'];
        // prettier-ignore
        let data = [220, 182, 191, 234, 290, 330, 310, 123, 442, 321, 90, 149, 210, 122, 133, 334, 198, 123, 125, 220];
        let yMax = 500;
        let dataShadow = [];
        for (let i = 0; i < data.length; i++) {
            dataShadow.push(yMax);
        }
        let option2 = {
            title: {
                text: '特性示例：渐变色 阴影 点击缩放',
                subtext: 'Feature Sample: Gradient Color, Shadow, Click Zoom'
            },
            xAxis: {
                data: dataAxis,
                axisLabel: {
                inside: true,
                color: '#fff'
                },
                axisTick: {
                show: false
                },
                axisLine: {
                show: false
                },
                z: 10
            },
            yAxis: {
                axisLine: {
                show: false
                },
                axisTick: {
                show: false
                },
                axisLabel: {
                color: '#999'
                }
            },
            dataZoom: [
                {
                type: 'inside'
                }
            ],
            series: [
                {
                type: 'bar',
                showBackground: true,
                itemStyle: {
                    color: proxy.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                    { offset: 0, color: '#83bff6' },
                    { offset: 0.5, color: '#188df0' },
                    { offset: 1, color: '#188df0' }
                    ])
                },
                emphasis: {
                    itemStyle: {
                    color: proxy.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        { offset: 0, color: '#2378f7' },
                        { offset: 0.7, color: '#2378f7' },
                        { offset: 1, color: '#83bff6' }
                    ])
                    }
                },
                data: data
                }
            ]
            };
            // Enable data zoom when user click bar.
            const zoomSize = 6;
            myChart2.on('click', function (params) {
            console.log(dataAxis[Math.max(params.dataIndex - zoomSize / 2, 0)]);
            myChart2.dispatchAction({
                type: 'dataZoom',
                startValue: dataAxis[Math.max(params.dataIndex - zoomSize / 2, 0)],
                endValue:
                dataAxis[Math.min(params.dataIndex + zoomSize / 2, data.length - 1)]
            });
        });
        option2 && myChart2.setOption(option2);
    });
</script>
